﻿using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
using Dominion.Core;

namespace Dominion.WPF.Services
{
    internal class ServiceLocator
    {

        static ServiceLocator()
        {
            map = new Dictionary<Type, object>();
            ServiceLocator.RegisterService<INotificationService>(new MessageBoxService());
        }

        private ServiceLocator() { }


        private static IDictionary<Type, object> map;

        public static T GetService<T>() where T : class
        {
            object service;
            map.TryGetValue(typeof(T), out service);
            return service as T;

        }



        public static bool RegisterService<T>(T service)
        {
            bool rc = false;
            if (!map.Keys.Contains(typeof(T)))
            {
                map.Add(typeof(T), service);
                rc = true;
            }
            return rc;
        }

    }
}
